package com.mmall.controller;

import com.github.pagehelper.PageInfo;
import com.mmall.common.ServerResponse;
import com.mmall.param.AclParam;
import com.mmall.pojo.SysAcl;
import com.mmall.pojo.SysRole;
import com.mmall.service.ISysAclService;
import com.mmall.service.ISysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author wangtengyu
 * @Create 2018-03-14-11:54
 */
@Controller
@RequestMapping("/sys/acl")
public class SysAclController {

    @Autowired
    private ISysAclService iSysAclService;

    @Autowired
    private ISysRoleService iSysRoleService;


    /**
     * 新增权限点
     * @param param
     * @return
     */
    @RequestMapping("/save.json")
    @ResponseBody
    public ServerResponse saveAcl(AclParam param){
        iSysAclService.save(param);
        return ServerResponse.createBySuccess("新增权限点成功");
    }

    /**
     * 更新权限点
     * @param param
     * @return
     */
    @RequestMapping("/update.json")
    @ResponseBody
    public ServerResponse updateAcl(AclParam param){
        iSysAclService.update(param);
        return ServerResponse.createBySuccess("更新权限点成功");
    }

    /**
     * 返回分页结果
     * @param aclModuleId
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping("/list.json")
    @ResponseBody
    public ServerResponse getAclList(int aclModuleId,int pageNum,int pageSize){
        PageInfo<SysAcl> pageInfo=iSysAclService.getAclList(aclModuleId,pageNum,pageSize);
        return ServerResponse.createBySuccess(pageInfo);

    }

    /**
     * 删除
     * @param aclId
     * @return
     */
    @RequestMapping("delete.json")
    @ResponseBody
    public ServerResponse delete (@RequestParam("id") int aclId){
        iSysAclService.delete(aclId);
        return ServerResponse.createBySuccess("删除权限成功");
    }


    @RequestMapping("aclbindedRole.json")
    @ResponseBody
    public ServerResponse aclbindedRole(@RequestParam("aclId") int aclId){
        List<SysRole> roleList=iSysRoleService.getRoleListByAclId(aclId);
        return ServerResponse.createBySuccess(roleList);
    }




}
